package com.zaoke.web.dao.order.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.zaoke.web.bo.order.OrderFood;
import com.zaoke.web.dao.JdbcSupport;
import com.zaoke.web.dao.order.OrderFoodDao;

public class OrderFoodDaoImpl extends JdbcSupport implements OrderFoodDao{

	@Override
	public List<OrderFood> getOrderFoodsByOrderid(Long orderid) {
		
		String sql = "select * from zaoke.order_food where order_id=?";
		List<OrderFood> res = getTemplateMgr().getReadTp().query(sql, new RowMapper<OrderFood>() {

			@Override
			public OrderFood mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				OrderFood orderfood = new OrderFood();
				orderfood.setFoodname(rs.getString("food_name"));
				orderfood.setFoodtype(rs.getInt("food_type"));
				orderfood.setOrderid(rs.getLong("order_id"));
				orderfood.setPrice(rs.getDouble("sale_price"));
				orderfood.setUserid(rs.getLong("user_id"));
				orderfood.setFoodid(rs.getLong("food_id"));
				
				return orderfood;
			}
		}, orderid);
		return res;
	}

}
